<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增页面</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/component/pear/css/pear.css" />
</head>
<body>
<form class="layui-form" action="" method="">
    <div class="mainBox">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label">部门名称:</label>
                <div class="layui-input-block">
                    <input type="text" style="width: 400px"	 name="deptName" lay-verify="title" autocomplete="off" placeholder="请输入部门名称"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">父部门id:</label>
                <div class="layui-input-block">
                    <input type="text" style="width: 400px" name="parentId" lay-verify="title" autocomplete="off" placeholder="请输入父级Id"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">组级列表:</label>
                <div class="layui-input-block">
                    <input type="text" style="width: 400px" name="ancestors" lay-verify="title" autocomplete="off" placeholder="请输入请求地址"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">部门状态:</label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="0" title="正常" checked>
                    <input type="radio" name="status" value="1" title="停用">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">负者人:</label>
                <div class="layui-input-block">
                    <input type="text" style="width: 400px" name="leader" lay-verify="title" autocomplete="off" placeholder="负责人名称"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">联系电话:</label>
                <div class="layui-input-block">
                    <input type="text" style="width: 400px" name="phone" lay-verify="title" autocomplete="off" placeholder="请输入电话号码"
                           class="layui-input">
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="dept-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script src="${pageContext.request.contextPath}/statics/component/layui/layui.js"></script>
<script src="${pageContext.request.contextPath}/statics/component/pear/pear.js"></script>
<script>
    layui.use(['form', 'jquery'], function() {
        let form = layui.form;
        let $ = layui.jquery;

        form.on('submit(dept-save)', function(data) {
            $.ajax({
                url: '${pageContext.request.contextPath}/dept/deptadd',
                data: data.field,
                dataType: 'json',
                // contentType: 'application/json',
                type: 'post',
                success: function(result) {
                    if (result = 1) {
                        layer.msg(result.msg, {
                            icon: 1,
                            height:200,
                            time: 1000
                        }, function() {
                            parent.layer.close(parent.layer.getFrameIndex(window
                                .name)); //关闭当前页
                            parent.layui.table.reload("dept-table");
                        });
                    } else {
                        layer.msg(result.msg, {
                            icon: 2,
                            time: 1000
                        });
                    }
                }
            })
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>